/***********************************************************************
	filename: 	CEGUIImage.h
	created:	13/3/2004
	author:		Paul D Turner
	
	purpose:	Defines interface for Image class
*************************************************************************/
#ifndef _HgeImage_h_
#define _HgeImage_h_

#include "hgeForwardRef.h"
#include "hgeVector.h"
#include "hgeRect.h"
#include "hgecolor.h"
#include "hgeRenderer.h"
#include <map>
#include <string>

#if defined(_MSC_VER)
#	pragma warning(push)
#	pragma warning(disable : 4251)
#endif


/*!
\brief
	Class that represents a single Image of an Imageset.
*/
class Image
{
public:
	Size	getSize(void) const			{return Size(d_scaledWidth, d_scaledHeight);}
	float	getWidth(void) const		{return d_scaledWidth;}
	float	getHeight(void) const		{return d_scaledHeight;}
	Point	getOffsets(void) const		{return d_scaledOffset;}
	float	getOffsetX(void) const		{return	d_scaledOffset.d_x;}
	float	getOffsetY(void) const		{return d_scaledOffset.d_y;}
	const	String&	getName(void) const;
    const	hgeRect& getSourceTextureArea(void) const;

    //Queue the image to be drawn.
    void draw(GeometryBuffer& buffer, const Vector2& position, const Size& size,
              const hgeRect* clip_rect,
              const colour& top_left_colour = 0xFFFFFFFF,
              const colour& top_right_colour = 0xFFFFFFFF,
              const colour& bottom_left_colour = 0xFFFFFFFF,
              const colour& bottom_right_colour = 0xFFFFFFFF,
              QuadSplitMode quad_split_mode = TopLeftToBottomRight) const
    {
		hgeRect rt(position.d_x, position.d_y, position.d_x + size.d_x, position.d_y + size.d_y);
        draw(buffer, rt, clip_rect, ColourRect(top_left_colour, top_right_colour, bottom_left_colour,
                        bottom_right_colour),
             quad_split_mode);
    }

    void draw(GeometryBuffer& buffer, const hgeRect& dest_rect,
              const hgeRect* clip_rect,
              const colour& top_left_colour = 0xFFFFFFFF,
              const colour& top_right_colour = 0xFFFFFFFF,
              const colour& bottom_left_colour = 0xFFFFFFFF,
              const colour& bottom_right_colour = 0xFFFFFFFF,
              QuadSplitMode quad_split_mode = TopLeftToBottomRight) const
    {
        draw(buffer, dest_rect, clip_rect,
             ColourRect(top_left_colour, top_right_colour,
                        bottom_left_colour, bottom_right_colour),
             quad_split_mode);
    }

    void draw(GeometryBuffer& buffer, const Vector2& position, const Size& size,
              const hgeRect* clip_rect, const ColourRect& colours,
              QuadSplitMode quad_split_mode = TopLeftToBottomRight) const
    {
		hgeRect rt(position.d_x, position.d_y, position.d_x + size.d_x, position.d_y + size.d_y);
        draw(buffer, rt, clip_rect, colours, quad_split_mode);
    }

    void draw(GeometryBuffer& buffer, const Vector2& position,
              const hgeRect* clip_rect, const ColourRect& colours,
              QuadSplitMode quad_split_mode = TopLeftToBottomRight) const
    {
        draw(buffer, hgeRect(position.d_x, position.d_y,
                          position.d_x + getWidth(),
                          position.d_y + getHeight()),
             clip_rect, colours, quad_split_mode);
    }

    void draw(GeometryBuffer& buffer, const Vector2& position,
              const hgeRect* clip_rect,
              const colour& top_left_colour = 0xFFFFFFFF,
              const colour& top_right_colour = 0xFFFFFFFF,
              const colour& bottom_left_colour = 0xFFFFFFFF,
              const colour& bottom_right_colour = 0xFFFFFFFF,
              QuadSplitMode quad_split_mode = TopLeftToBottomRight) const
    {
        draw(buffer, hgeRect(position.d_x, position.d_y,
                          position.d_x + getWidth(),
                          position.d_y + getHeight()),
             clip_rect,
             ColourRect(top_left_colour, top_right_colour,
                        bottom_left_colour, bottom_right_colour),
             quad_split_mode);
    }

    void draw(GeometryBuffer& buffer, const hgeRect& dest_rect,
              const hgeRect* clip_rect, const ColourRect& colours,
              QuadSplitMode quad_split_mode = TopLeftToBottomRight) const;


	//friend class std::map<String, Image>;
	//friend struct std::pair<const String, Image>;

	/*************************************************************************
		Construction and Destruction
	*************************************************************************/
	//Default constructor (only used by std::map)
	Image(void) {}

	Image(Texture& texture, const String& name, const hgeRect& area, const Point& render_offset, float horzScaling = 1.0f, float vertScaling = 1.0f);
	Image(const String& filename, const String& name, const hgeRect& area, const Point& render_offset, float horzScaling, float vertScaling);
	Image(const String& filename, const String& name);
	Image(const Image& image);
	~Image(void);


private:
	/*************************************************************************
		Implementation Methods
	*************************************************************************/
	//set the horizontal scaling factor to be applied to this Image
	void	setHorzScaling(float factor);

	//set the vertical scaling factor to be applied to this Image
	void	setVertScaling(float factor);


	/*************************************************************************
		Implementation Data
	*************************************************************************/
	hgeRect			d_area;			//!< hgeRect defining the area on the texture that makes up this image.
	Point			d_offset;		//!< Offset to use when rendering
	Texture*		d_texture;

	// image auto-scaling fields.
	float	d_scaledWidth;		//!< scaled image width.
	float	d_scaledHeight;		//!< scaled image height.
	Point	d_scaledOffset;		//!< scaled rendering offset.
	String	d_name;				//!< name of this image.
};

#if defined(_MSC_VER)
#	pragma warning(pop)
#endif

#endif	// end of guard _CEGUIImage_h_
